/* eslint-disable import/no-cycle */
/**
 * 常量
 */

import { PixelRatio, Platform } from 'react-native';
import {
  getFreeDiskStorageSync,
  getTotalDiskCapacitySync
} from 'react-native-device-info';

import systemUtil from '../util/native/systemUtil';

export const APP_ID = 2;

export const isIOS = Platform.OS === 'ios';

// 手机物理分辨率(包括导航栏)
const { width, height } = systemUtil.getScreenPhysicalPixels();
const { availMemory, totalMemory } = systemUtil.getMemoryInfo();

// eslint-disable-next-line no-undef
export const DEBUG = __DEV__;

// 手机实际宽高(包含导航栏)
export const SCREEN_WIDTH = isIOS ? width : width / PixelRatio.get();
export const SCREEN_HEIGHT = isIOS ? height : height / PixelRatio.get();

export const TABLET_WIDTH = (Math.max(SCREEN_HEIGHT, SCREEN_WIDTH) * 360) / 640;

// 手机操作系统
export const OS_TYPE = Platform.OS;

// 操作系统版本
export const OS_VERSION = systemUtil.getOSVersion();

// cpu
export const CPU_NAME = systemUtil.getCpuName();

// cpu core num
export const CPU_CORE_NUM = systemUtil.getNumberOfCPUCores();

// device brand
export const DEVICE_BRAND = systemUtil.getDeviceProduct();

// device model
export const DEVICE_MODEL = systemUtil.getDeviceModel();

// app name
export const APP_NAME = 'com.mifengxiaoban.studygroup';

// channel
export const CHANNEL = systemUtil.getVersionChannel();

// app version
export const APP_VERSION = systemUtil.getAppVersion();

// device id
export const DEVICE_ID = systemUtil.getAppDeviceId();

// 是否是平板设备
export const IS_TABLET_DEVICE = systemUtil.getIsTabletDevice();

// 是否支持人脸识别
export const IS_SUPPORT_FACE_DETECTED = true; // systemUtil.isFaceDetectedSupported()

// 可用存储空间
export const AVAIL_MEMORY = isIOS
  ? getFreeDiskStorageSync() / 1024 / 1024 // Bytes -> KB -> MB
  : Number(availMemory); // MB

// 总存储空间
export const TOTAL_MEMORY = isIOS
  ? getTotalDiskCapacitySync() / 1024 / 1024 // Bytes -> KB -> MB
  : Number(totalMemory); // MB

// 设备是否有刘海
export const HAVE_NOTCH = systemUtil ? !!systemUtil.hasNotchInScreen() : false;

// 刘海宽度
export const NOTCH_WIDTH =
  systemUtil && HAVE_NOTCH
    ? systemUtil.getNotchWidth() / (isIOS ? 1 : PixelRatio.get())
    : 0;

export const CODE_PUSH_KEY = systemUtil.getCodePushKey();

// 弹框
export const GLOBAL_MODEL = 'GLOBAL_MODEL';

// 提示文本框
export const GLOBAL_TOOLTIP = 'GLOBAL_TOOLTIP';

// 全局 菊花
export const GLOBAL_LOADING = 'GLOBAL_LOADING';

// 提示文本框默认显示时间 1500 ms
export const TOOLTIP_TIMER = 1500;

// android 设备brand
export const DEVICE_BRAND_VIVO = 'vivo';

// 是否是新用户
export const STORAGE_KEY_IS_FIRST_TRY = 'isFirstTry';

// 用户信息
export const STORAGE_KEY_USER_INFO = 'userInfo';

// 开发相关
export const STORAGE_KEY_DEVELOP = 'develop';

// appConfig
export const STORAGE_KEY_APP_CONFIG = 'appConfig';

// ClassRoom相关
export const STORAGE_KEY_CLASSROOM = 'classRoom';

// 省市区信息
export const STORAGE_KEY_DISTRICT_INFO = 'districtInfo';

export const STORAGE_KEY_AGREEMENT = 'agreement';
export const STORAGE_KEY_AIP_TOKEN = 'aipToken';

// 灰度配置
export const STORAGE_KEY_GRAY = 'gray';

// 是否第一次视频引导调进度
export const STORAGE_KEY_IS_FIRST_SHOW_PROGRESS_GUIDE = 'progressGuide';

// onNavigationStateChange回调的其中一个case，在这个时机下，来做页面访问埋点
export const NAVIGATION_COMPLETE_TRANSITION = 'Navigation/COMPLETE_TRANSITION';

// 是否放开游客入口
export const OPEN_GUEST_ENTRY = 'openGuestEntry';

// 互动题webview
export const PROBLEM_WEBVIEW = 'problemWebview';

// 用户被踢出登录事件名
export const EVENT_KICKED_OUT = 'kickedOut';

// 用户协议url
export const CHORES_SERVICE_URL =
  'https://h5.mifengxiaoban.com/aikid/choresService/';

// 隐私政策url
export const PRIVACY_URL = 'https://h5.mifengxiaoban.com/aikid/privacy/';

// 埋点公共字段
export const EVENT_COMMON_PARAM = {
  osType: OS_TYPE,
  osVersion: OS_VERSION,
  screenResolution: `${width}*${height}`,
  cpu: CPU_NAME,
  cpuCoreNum: CPU_CORE_NUM,
  storageFree: AVAIL_MEMORY,
  storageTotal: TOTAL_MEMORY,
  deviceBrand: DEVICE_BRAND,
  deviceModel: DEVICE_MODEL
};

// 付款方式 1-微信，2-支付宝，3-代金卡，4-ApplePay，5-IAP，6-蜜蜂币，7-全额优惠卡
export enum PayMethod {
  Unknown,
  WeChat = 1,
  AliPay = 2,
  YuTouCoin = 6
}

export const PayMethodText: { [key: number]: string } = {
  [PayMethod.WeChat]: '微信支付',
  [PayMethod.AliPay]: '支付宝支付',
  [PayMethod.YuTouCoin]: '蜜蜂币支付'
};

// 灰度
export const GRAY_USE_RN_VIDEO = 'useRnVideo'; // 使用react-native-video播放器
export const GRAY_NOT_USE_BIG_CHANNEL = 'notUseBigChannel'; // 不使用声网大班
export const GRAY_NEED_MANUAL_SIGN_IN = 'manualSignIn'; // 手动签到

export enum Permission {
  Denied = -1,
  Granted = 0
}
